$(function () {
	init();
	listenbutton();
})

function listenbutton() {
	$("#submit").click(function () {
		$.ajax({
			cache: true,
			type: "POST",
			url: "../User/AddUser",
			data: $('#myFrom').serialize(), // 你的formid
			async: false,
			error: function (request) {
				alert("修改失败");
			},
			success: function (data) {
				if (data == "success") {
					alert("修改成功");
				} else {
					alert("修改失败");
				}
			}
		});

	})


}

function init() {
	var validator = $("#myFrom").bind(
		"invalid-form.validate",
		function () {
			$("#validateForm").html(
				"表单包含 " + validator.numberOfInvalids() + "个错误！");
		}).validate({
		//debug : true,
		errorElement: "span",
		errorPlacement: function (error, element) {
			error.appendTo(element.parent("div").next(
				"label.control-label-left"));
		},
		success: function (label) {
			label.html('<i class="glyphicon glyphicon-ok"></i>');
		},
		rules: {

			userName: {
				required: true,
				minlength: 2,
				maxlength: 10
			},
			userPassword: {
				required: true,
				minlength: 3,
				maxlength: 20
			},
			age: {
				digits: true,
			},
			position: {
				maxlength: 20
			},
			educationLevel: {
				maxlength: 20
			},
			workingPlace: {
				maxlength: 20,
			}
		},
		messages: {

			userName: {
				required: "请输入真实名称",
				minlength: "用户名不得少于2位",
				maxlength: "真实名称最长为10位"
			},
			userPassword: {
				required: "请输入用户密码",
				maxlength: "最大长度不能超过20字",
				minlength: "密码不得少于3位"
			},
			age: {
				digits: "年龄必须为数字",
			},
			position: {
				maxlength: "最大长度不能超过20字",
			},
			educationLevel: {
				maxlength: "最大长度不能超过20字",
			},
			workingPlace: {
				maxlength: "工作地点最大长度不能超过20字"
			}
		}
	});

}

/*
 * 
 * j.post("getManageInstitutionNamesList",null,function(data,textStatus) {
 * if(textStatus=="success") { var map = j.parseJSON(data)["map"]; for(var key
 * in map) { var temp='<option value="'+key+'">'+map[key]+'</option>';
 * j(temp).appendTo("#selectPerson"); }
 *  }
 * 
 * });
 * 
 * 
 * 
 */